package jch.learn.java.advanced.chapter2_InputAndOutput;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class Test1 {

    public static void main(String[] args){
        System.out.println("获取键盘输入：");
        Reader in = new InputStreamReader(System.in);
        try {
            System.out.println(in.read()); // 读取字节
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            // 读取文件
            in = new InputStreamReader(new FileInputStream(Test1.class.getResource("/data.txt").getPath()), StandardCharsets.UTF_8);
            char[] chars = new char[10];
            in.read(chars);// 将从文件中读取到的数据写入到chars数组。
            System.out.println(Arrays.toString(chars));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
